﻿using Assets.Script.Config;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerManager : MonoBehaviour
{
    public static int PlayerNum = 1;
    public static PlayerData[] playerDatas = new PlayerData[] { new PlayerData() };

    private static GameObject player;
    private static GameObject PlayerAim_Canvas;
    private void Awake()
    {
        if (player==null)
        {
            player = Resources.Load<GameObject>(ResourcePath.Player);
            if (player==null)
            {
                Debug.Log("bad");
            }
        }
        if (PlayerAim_Canvas == null)
        {
            PlayerAim_Canvas = Resources.Load<GameObject>(ResourcePath.PlayerAim_Canvas);
            if (PlayerAim_Canvas == null)
            {
                Debug.Log("bad");
            }
        }

        for (int i = 0; i < playerDatas.Length; i++)
        {
            var clo_player = Instantiate(player, Vector3.zero, new Quaternion(), null);
            

            InputRead.GetDic().Add(i, new Configs.InputReaderMan());
            clo_player.GetComponentInChildren<PlayerBody>().Init(playerDatas[i], i);


            var clo_playerAim = Instantiate(PlayerAim_Canvas, Vector3.zero, new Quaternion(), Camera.main.transform);
            clo_playerAim.GetComponentInChildren<AimCOM>().Init(InputRead.GetID(i));
            clo_playerAim.GetComponentInChildren<Canvas>().worldCamera= Camera.main;

            if (i==0)
            {
                Camera.main.GetComponent<CameraCom>().Init(clo_player.transform);
            }
        }
        
    }
}
